package com.lyy.component;

import com.lyy.entity.Order;
import com.lyy.entity.User;
import com.lyy.entity.Video;
import com.lyy.mapper.OrderMapper;
import com.lyy.mapper.UserMapper;
import com.lyy.mapper.VideoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Liangyaoyun
 */
@Slf4j
@Component
public class CleatInvalidDataTask {
    @Autowired
    private UserMapper userMapper;

    /**
     * 每天凌晨2点半，删除一次无效数据
     */
    @Transactional(rollbackFor = Exception.class)
    @Scheduled(cron = "0 30 02 * * ?")
    public void clearInvalidData() {

        // 删除无效的User记录（即 userDeleted = 1 的记录）
        User userCondition = new User();
        userCondition.setUserDeleted(1);
        int userResult = userMapper.delete(userCondition);

        // 记录日志
        log.info("定时任务执行完毕，共清除 " + userResult + " 条无效用户记录");
    }
}
